﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;

namespace DAO
{
    public class XuatXuDAO
    {
        public List<XuatXuDTO> LayDanhSachXuatXu()
        {
            List<XuatXuDTO> danhsach = new List<XuatXuDTO>();
            string sql = "Select * From XUATXU";

            SqlConnection conn = DataProvider.ConnectDB();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                XuatXuDTO xxDTO = new XuatXuDTO();
                xxDTO.MaXuatXu = reader.GetInt32(0);
                xxDTO.TenXuatXu = reader.GetString(1);
                danhsach.Add(xxDTO);
            }
            conn.Close();
            return danhsach;
        }
        public string LayTenXuatXuTheoMa(int maXX)
        {
            string tenxx = "";
            string sql = "Select TenXuatXu From XUATXU Where MaXuatXu= " + maXX ;

            SqlConnection conn = DataProvider.ConnectDB();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
               tenxx = reader.GetString(0);
            }
            conn.Close();
            return tenxx;
        }
        public int LayMaXuatXuTheoTen(string ten)
        {
            int ma = 0;
            string sql = "Select MaXuatXu From XUATXU Where TenXuatXu= " + "N'" + ten + "'";

            SqlConnection conn = DataProvider.ConnectDB();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                ma = reader.GetInt32(0);
            }
            conn.Close();
            return ma;
        }
    }
}
